package com.sky.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @ClassName: RedisConfiguration
 * @Package: com.sky.config
 * @Author: 金磊
 * @CreateDate: 2025/4/10 - 18:36
 * @Version: V1.0.0
 * @Description:
 */
@Configuration
@Slf4j
public class RedisConfiguration {
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        log.info("RedisTemplate初始化开始");
        RedisTemplate redisTemplate = new RedisTemplate();
        // 设置连接工厂
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        // 设置key的序列化器
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        // 设置value的序列化器
//        redisTemplate.setValueSerializer(new StringRedisSerializer());
        // 设置hash的key的序列化器
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        // 设置hash的value的序列化器
        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
        // 设置默认序列化器
//        redisTemplate.setDefaultSerializer(new StringRedisSerializer());
//        // 设置序列化器
//        redisTemplate.setEnableTransactionSupport(true);
//        // 设置事务支持
//        redisTemplate.afterPropertiesSet();
        log.info("RedisTemplate初始化完成");
        // 返回RedisTemplate对象
        return redisTemplate;
    }
}
